<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增产品规格管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-partsattribute-add">
            <input id="partsId" name="partsId" th:value="${partsId}" type="hidden">
            <input id="attributeLogo" name="attributeLogo" class="form-control" type="hidden" required>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">规格图：</label>
                        <div class="col-sm-8">
                            <p class="user-info-head" onclick="avatarAttribute()"><img id="attributeLogoShow" class="img-thumbnail img-lg" ></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">规格名称：</label>
                        <div class="col-sm-8">
                            <input name="attributeName" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label ">补助金金额：</label>
                        <div class="col-sm-8">
                            <input name="attributePayPrice" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">合同价：</label>
                        <div class="col-sm-8">
                            <input name="attributeContractPrice" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">销售价：</label>
                        <div class="col-sm-8">
                            <input name="attributeSalePrice" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">补助金有效期（单位）</label>
                        <div class="col-sm-8">
                            <input name="attributeWarranty" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">二维码有效期（单位）</label>
                        <div class="col-sm-8">
                            <input name="attributeInstall" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">统一零售价：</label>
                        <div class="col-sm-8">
                            <input name="attributeRetailPrice" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">统一批发价：</label>
                        <div class="col-sm-8">
                            <input name="attributeWholesalePrice" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">订购最低数量：</label>
                        <div class="col-sm-8">
                            <input name="attributeQuantity" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">最低批发价：</label>
                        <div class="col-sm-8">
                            <input name="attributeLowestPrice" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>-->

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">会长是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowProvice_' + dict.dictCode}" name="isShowProvice" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowProvice_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件店是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowCity_' + dict.dictCode}" name="isShowCity" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowCity_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">维修师傅是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowWorker_' + dict.dictCode}" name="isShowWorker" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isShowWorker_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否包邮：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isPost_' + dict.dictCode}" name="isPost" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                                <label th:for="${'isPost_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">备注(会长端)：</label>
                        <div class="col-sm-8">
                            <textarea name="attributeRemarks" class="form-control" required></textarea>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">备注(店铺端)：</label>
                        <div class="col-sm-8">
                            <textarea name="attributeStoreRemarks" class="form-control" required></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品品牌：</label>
                        <div class="col-sm-8">
                            <select name="attributeDistinguish" class="form-control m-b" th:with="type=${@dict.getType('parts_brand')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">产品优势描述：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="attributeAdvantage">
                    <div class="summernote" id="attributeAdvantage"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品使用说明书：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="attributeInstructions">
                    <div class="summernote" id="attributeInstructions"></div>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/partsattribute"
        $("#form-partsattribute-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-partsattribute-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/uploadOSS',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/uploadOSS",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        /*营业执照管理*/
        function avatarAttribute() {
            var url = ctx + 'zsyh/partsattribute/avatarAttribute?attributeLogo='+$("#attributeLogo").val();
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', $(window).height() + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "上传规格图片",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                    var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>
</body>
</html>